<?php
    //初始化
    $curl = curl_init();
    //设置url
    curl_setopt($curl, CURLOPT_URL, 'http://iot-i.cn:9900/faas/rfid');
    //设置头文件的信息作为数据流输出
    //curl_setopt($curl, CURLOPT_HEADER, 1);
    curl_setopt( $curl, CURLOPT_HTTPHEADER, array('Content-Type:application/json'));
    //设置获取的信息以文件流的形式返回，而不是直接输出。
    curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
    //设置post方式提交
    curl_setopt($curl, CURLOPT_POST, 1);
    // device id
    $device_id = "m_test_1b9c22af";
    // rfids to add or delete with 0102030405 and f1f2f3f4f5
    $rfids = "0102030405f1f2f3f4f5";

    //设置post数据
    $post_data = array(
        "username" => "test",
        "passwd" => "test",
        "device_id" => $device_id,
        "op" => "ledstatus",
        "ledstatus" => "1", 
    );
    curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($post_data));
    //执行命令
    print_r("添加rfid\n");
    $data = curl_exec($curl);
    //显示获得的数据
    print_r($data);
    print_r("\n");

    // device id
    print_r("删除rfid\n");    
    $post_data = array(
        "username" => "test",
        "passwd" => "test",
        "rfids" => $rfids, 
        "device_id" => $device_id    
    );
   
    curl_setopt($curl, CURLOPT_POSTFIELDS, json_encode($post_data));
    //执行命令
    //$data = curl_exec($curl);
    print_r($data); 

    print_r("\n");
    //关闭URL请求
    curl_close($curl);
?>
